package com.easyCode.sqlMapper.renderHandler;

import com.easyCode.sqlMapper.mapInfo.TableMapInfo;
import com.easyCode.sqlMapper.template.RenderHandler;
import com.easyCode.sqlMapper.template.SqlTemplateConfig;
import com.easyCode.sqlMapper.template.TemplateContext;
import org.apache.velocity.VelocityContext;

/**
 * @author 大忽悠
 * @create 2022/12/3 19:41
 */
public class VoRenderHandler implements RenderHandler<VelocityContext> {
    @Override
    public String paramPrepare(VelocityContext velocityContext, TableMapInfo tableMapInfo, SqlTemplateConfig sqlTemplateConfig, TemplateContext templateContext) {
        velocityContext.put("packagePath", sqlTemplateConfig.getVoModuleName());
        velocityContext.put("className",tableMapInfo.getTableName());
        velocityContext.put("filedList", tableMapInfo.getFiledMapInfos());
        velocityContext.put("tableMapInfo", tableMapInfo);
        //vo对象中默认不包含主键字段
        velocityContext.put("primaryName",tableMapInfo.getPrimaryKeyName());;

        templateContext.setVal(TemplateContext.JAVA_FILE_NAME,tableMapInfo.getTableName()+"Vo.java");

        return sqlTemplateConfig.getVoModuleName();
    }
}
